//This program will run a simulation of the Randy Hall paradox
import java.util.Random;
import java.util.Scanner;
public class Dox {
	static Random rand=new Random();
	public static void main(String[] args){
	Scanner input=new Scanner(System.in);
	int drs; //Number of doors
	int prz; //Number of prizes
	int hit; //Number of hits
	int mis; //Number of misses
	System.out.println("How many doors are there?");
	drs=input.nextInt();
	System.out.println("How many doors contain prizes");
	prz=input.nextInt();
	if (prz>=drs){ /* These lines ensure a valid ratio is used */
		System.out.println("Your ratio of prizes to doors was invalid. Running again.");
		main(args);
	}
	int[] doors=new int[drs];
	doors=assign(drs,doors,prz);
	double sty=stay(doors);
	sty=sty*100;
	System.out.println("Not switching yeilded a score "+sty+"% oif the time.");
	
	
	}
	static int[] assign(int doors, int[] door, int prizes){
		int selc=0;
		int num=0;
		boolean run=true;
		for(int i=0; i<doors; i++){ //Runs through each door
			num++;
			if (selc>prizes){ //Breaks if maximum amount of prizes is hit
				break;
			}
			else {
				int assign=rand.nextInt(2); //Assigns a value of 1 or 0 to every door, corresponding with an empty door or a prize.
				if (door[i]==0){
				door[i]=assign;
				}
				if (door[i]==1){
					selc++;
				}

			}
		}
		selc=0;
		num=0;
		for (int i=0;i<door.length;i++){
			if (door[i]==1){
				num++;
			}
		}
		if (num==prizes){
			return door;
		}
		else{
			assign(doors,door,prizes);
		}
		return door;
	}
	static double stay(int[] doors){
		int hit=0;
		for (int i=0;i<1000;i++){
			int choose=rand.nextInt(doors.length);
			if (doors[choose]==1){
				hit++;
			}
		}
		return hit/1000;
	}

}
